package com.huike.web.controller.report;


import com.huike.business.service.ITbBusinessService;
import com.huike.business.service.impl.TbBusinessServiceImpl;
import com.huike.clues.domain.vo.IndexStatisticsVo;
import com.huike.common.core.domain.AjaxResult;
import com.huike.report.service.IReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/index")
public class IndexController {
    @Autowired
    private IReportService iReportService;

    @Autowired
    private ITbBusinessService iTbBusinessService;

    @GetMapping("/salesStatistic")
    public AjaxResult salesStatistic(String beginCreateTime,String endCreateTime){
        IndexStatisticsVo statisticsVo = new IndexStatisticsVo();
        statisticsVo.setBeginCreateTime(beginCreateTime);
        statisticsVo.setEndCreateTime(endCreateTime);
        List<Map<String, Object>> list = iReportService.salesStatistic(statisticsVo);
        return AjaxResult.success(list);
    }
    @GetMapping("/businessChangeStatistics")
    public AjaxResult businessChangeStatistics(String beginCreateTime,String endCreateTime){
        IndexStatisticsVo statisticsVo = new IndexStatisticsVo();
        statisticsVo.setBeginCreateTime(beginCreateTime);
        statisticsVo.setEndCreateTime(endCreateTime);
        List<Map<String, Object>> list = iTbBusinessService.businessChangeStatistics(statisticsVo);
        return  AjaxResult.success(list) ;
    }

    @GetMapping()
    public AjaxResult contractStatistics(IndexStatisticsVo request){
        SimpleDateFormat sdf = new SimpleDateFormat();
        request.setBeginCreateTime(request.getBeginCreateTime()+" 00:00:00");
        request.setEndCreateTime(request.getEndCreateTime()+" 23:59:59");
        Map<String,Object> result = iReportService.getcontractsBasicInfo(request,sdf.format(new Date()));
        return AjaxResult.success(result);
    }

}
